/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cvs;

import Obj.configBttv;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author dragon
 */
public class ReadCSV {

    public ArrayList readCVS(String csvFile, boolean esCard) {

        ArrayList listaCards = new ArrayList();

        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";

        try {

            br = new BufferedReader(new FileReader(csvFile));
            while ((line = br.readLine()) != null) {
                configBttv obj = new configBttv();
                String[] data = line.split(cvsSplitBy);

                obj.setNumero(data[0]);
                if (esCard) {
                    obj.setDescriCard(data[1]);
                } else {
                    obj.setDescriTuner(data[1]);
                }
                //obj.setPuntos(Integer.parseInt(data[2]));

                // use comma as separator
                //System.out.println(data[0] + " ; " + data[1]);
                listaCards.add(obj);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        System.out.println("Done List " + csvFile);
        return listaCards;
    }

    public ArrayList readCVS(String csvFile) {

        ArrayList listaCards = new ArrayList();

        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";

        try {

            br = new BufferedReader(new FileReader(csvFile));
            while ((line = br.readLine()) != null) {
                configBttv obj = new configBttv();
                String[] data = line.split(cvsSplitBy);

                obj.setNumero(data[0]);
                obj.setDescriCard(data[1]);
                obj.setDescriTuner(data[2]);
                obj.setPuntos(Integer.parseInt(data[3]));

                // use comma as separator
                //System.out.println(data[0] + " ; " + data[1]);
                listaCards.add(obj);
            }

        } catch (FileNotFoundException e) {
            return  new ArrayList();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        System.out.println("Done List " + csvFile);
        return listaCards;
    }
}
